home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Include / FWDelSta.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  6.3 KB  |  211 lines  |  [TEXT/MPS ]

  1. #ifndef FWDELSTA_H
  2. #define FWDELSTA_H
  3.  
  4. //========================================================================================
  5. //
  6. //    File:                FWDelSta.h
  7. //    Release Version:    $ 1.0d11 $
  8. //
  9. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef FW_NATIVE_EXCEPTIONS
  14.  
  15. #ifndef   FWEXCTAS_H
  16. #include "FWExcTas.h"
  17. #endif
  18.  
  19. #ifndef   FWPRIDEB_H
  20. #include "FWPriDeb.h"
  21. #endif
  22.  
  23. #ifndef   FWEXCRUN_H
  24. #include "FWExcRun.h"
  25. #endif
  26.  
  27. #ifndef   FWCLAINF_H
  28. #include "FWClaInf.h"
  29. #endif
  30.  
  31. #if FW_LIB_EXPORT_PRAGMAS
  32. #pragma lib_export on
  33. #endif
  34.  
  35. class FW_CLASS_ATTR FW_CPrivDeleteStack;
  36. class FW_CLASS_ATTR FW_CPrivDeleteEntry;
  37. class FW_CLASS_ATTR _FW_CAutoDestructObject;
  38.  
  39. //========================================================================================
  40. // CLASS FW_CPrivDeleteEntry
  41. //========================================================================================
  42.  
  43. class FW_CLASS_ATTR FW_CPrivDeleteEntry
  44. {
  45. public:
  46.  
  47.     enum __DeleteType
  48.     {
  49.         __kObject,
  50.         __kGuard,
  51.         __kDeleted,
  52.         __kInvalid
  53.     };
  54.  
  55.     __DeleteType fType;
  56.     union 
  57.     {
  58.         _FW_CAutoDestructObject * fObject;
  59.         FW_ClassInfoPtr fGuard;
  60.     };
  61.  
  62.     void *fObjectVTable; // The objects v table at time of construction
  63.     
  64.     FW_CPrivDeleteEntry(_FW_CAutoDestructObject * anObject);
  65.     FW_CPrivDeleteEntry(FW_ClassInfoPtr  guard);
  66.  
  67.     __DeleteType GetType();
  68.     void SetType(__DeleteType type);
  69.     FW_ClassInfoPtr GetGuard();
  70.     _FW_CAutoDestructObject *GetObject();
  71. };
  72.  
  73.  
  74. //========================================================================================
  75. // CLASS FW_CPrivDeleteStack
  76. //
  77. //    The delete stack is maintained as an array of pointers to DeleteEntry, and three
  78. //    pointers into the array.  The three pointers are the StackBase, StackTop, and 
  79. //    StackLimit.  The StackBase points to the beginning of the array, the StackLimit points
  80. //    one past the last position in the array, and the StackTop points one past the last
  81. //    pushed item.  When the stack is empty, StackBase == StackTop.  When the stack is 
  82. //    full StackTop == StackLimit.  If an item is pushed when the stack is full, it is
  83. //    resized, which may move the array, so all three pointers need to be updated.  To do
  84. //    this, an integer offset RelativeTopOfStack is sometimes used to remember the location
  85. //    of a StackTop across code that might resize the stack.
  86. //
  87. //    Class Invariants:
  88. //        GetStackBase() != NULL
  89. //        GetStackBase() <= GetStackTop() <= GetStackLimit()
  90. //        GetStackTop() == GetStackBase() + RelativeTopOfStack()
  91. //        GetStackBase() + GetCurrentStackSize() == GetStackLimit()
  92. //========================================================================================
  93.  
  94. class FW_CLASS_ATTR FW_CPrivDeleteStack
  95. {
  96. public:
  97.     static void Initialize(FW_SPrivExceptionGlobals& globals);
  98.     static void Terminate();
  99.  
  100.     static inline void Push(_FW_CAutoDestructObject* anObject);
  101.     static inline void Push(FW_ClassInfoPtr  aGuard);
  102.  
  103.     static int IsClassExpectedInContext(FW_CPrivTryBlockContext *context, FW_ClassInfoPtr thrownType);
  104.         // Search for a guard that would prevent throwing this class to the next context.
  105.         // If we don't find such a guard then return true otherwise return false.
  106.  
  107.     static void PopOffAndDeleteObjectsInContext(FW_SPrivExceptionGlobals& globals, 
  108.                                                 FW_CPrivTryBlockContext *context);
  109.     static _FW_StackEntries RelativeTopOfStack(FW_SPrivExceptionGlobals& globals);
  110.     static void PopIfTopEquals(_FW_CAutoDestructObject* anObject);
  111.     static FW_ClassInfoPtr  PopGuard();
  112.  
  113. private:
  114.     static void Push(void * aGuardOrObject, FW_CPrivDeleteEntry::__DeleteType deleteType);
  115.  
  116.     enum
  117.     {
  118.         kNumberOfObjectsToGrowStack = 256,
  119.         kStepByteSize = kNumberOfObjectsToGrowStack * sizeof(FW_CPrivDeleteEntry)
  120.     };
  121.  
  122.     static void SetStackTop(FW_SPrivExceptionGlobals& globals, FW_CPrivDeleteEntry * pStackTop);
  123.  
  124. #ifdef FW_DEBUG
  125.     static void CheckClassInvariants(FW_SPrivExceptionGlobals& globals);
  126. #endif
  127. };
  128.  
  129. //========================================================================================
  130. // STRUCT FW_CPrivThrowGuard
  131. //========================================================================================
  132.  
  133. struct FW_CLASS_ATTR FW_CPrivThrowGuard
  134. {
  135. #ifdef FW_DEBUG
  136.     FW_ClassInfoPtr  fGuardClass;
  137. #endif
  138.     FW_CPrivThrowGuard();
  139.     FW_CPrivThrowGuard(FW_ClassInfoPtr  guard);
  140.     ~FW_CPrivThrowGuard();
  141. };
  142.  
  143. //========================================================================================
  144. // CLASS FW_CPrivDeleteEntry INLINE Functions
  145. //========================================================================================
  146.  
  147. inline FW_CPrivDeleteEntry::__DeleteType FW_CPrivDeleteEntry::GetType()
  148. {
  149.     return fType;
  150. }
  151.  
  152. inline void FW_CPrivDeleteEntry::SetType(__DeleteType type)
  153. {
  154.     fType = type;
  155. }
  156.  
  157. inline FW_ClassInfoPtr FW_CPrivDeleteEntry::GetGuard()
  158. {
  159.     FW_PRIV_ASSERT(fType == __kGuard);
  160.     return fGuard;
  161. }
  162.  
  163. inline _FW_CAutoDestructObject *FW_CPrivDeleteEntry::GetObject()
  164. {
  165.     FW_PRIV_ASSERT(fType == __kObject);
  166.     return fObject;
  167. }
  168.  
  169. //========================================================================================
  170. // CLASS FW_CPrivDeleteStack INLINE Functions
  171. //========================================================================================
  172.  
  173. inline void FW_CPrivDeleteStack::SetStackTop(FW_SPrivExceptionGlobals& globals, 
  174.                                           FW_CPrivDeleteEntry* pStackTop)
  175. {
  176. #ifdef FW_DEBUG
  177.     pStackTop->SetType(FW_CPrivDeleteEntry::__kInvalid);
  178. #endif
  179.     globals.gStackTop = pStackTop;
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. // FW_CPrivDeleteStack::RelativeTopOfStack
  184. //----------------------------------------------------------------------------------------
  185. inline _FW_StackEntries FW_CPrivDeleteStack::RelativeTopOfStack(FW_SPrivExceptionGlobals& globals)
  186. {
  187.     return globals.gStackTop - globals.gStackBase;
  188. }
  189.  
  190. //========================================================================================
  191. // CLASS FW_CPrivDeleteStack INLINE Functions (Platform independent versions)
  192. //========================================================================================
  193.  
  194. inline void FW_CPrivDeleteStack::Push(FW_ClassInfoPtr  aGuard)
  195. {
  196.     Push((void*) aGuard, FW_CPrivDeleteEntry::__kGuard);
  197. }
  198.  
  199. inline void FW_CPrivDeleteStack::Push(_FW_CAutoDestructObject* anObject)
  200. {
  201.     Push((void*) anObject, FW_CPrivDeleteEntry::__kObject);
  202. }
  203.  
  204. #if FW_LIB_EXPORT_PRAGMAS
  205. #pragma lib_export off
  206. #endif
  207.  
  208. #endif // FW_NATIVE_EXCEPTIONS
  209.  
  210. #endif
  211.